use std::sync::Arc;
use std::time::Duration;

use dbus::blocking::stdintf::org_freedesktop_dbus::*;
use dbus::blocking::Connection;
use dbus::blocking::Proxy;

use super::consts::*;

use super::Result;

mod nonblock;

#[test]
fn test_sys() -> Result<()> {
    let conn = Connection::new_system()?;
    let proxy = conn.with_proxy("org.bluez", "/", Duration::from_millis(500));
    let managed_objects = proxy.get_managed_objects()?;
    for (p, mo) in managed_objects {
        println!("{}", p);
        for (k, _v) in mo {
            print!("{}", k);
            if DBUS_BLUEZ_IFACE_ADAPTER == k.as_str() {
                println!(" (adapter {})", k);
            }
            print!("\n");
        }
        println!("");
    }

    Ok(())
}

#[test]
fn test_session() -> Result<()> {
    let conn = Connection::new_session()?;
    let proxy = conn.with_proxy("org.freedesktop.DBus", "/", Duration::from_millis(5000));
    let (names,): (Vec<String>,) = proxy.method_call("org.freedesktop.DBus", "ListNames", ())?;
    for name in names {
        println!("{}", name);
    }
    Ok(())
}
